/********************************************
 * 功能说明: Organization实体类对应的基础业务Repository
 * 模块名称:
 * 系统名称:
 * 软件版权: Frank
 * 系统版本: 1.0.0.1
 * 开发人员:
 * 开发时间: 2019-12-18 18:41:08
 * 审核人员:
 * 相关文档:
 * 修改记录: 修改日期 修改人员 修改说明
 *********************************************/
package com.spring.arch.uaa.repository;

import com.spring.arch.uaa.enums.OrganizationType;
import com.spring.arch.uaa.model.Organization;
import com.spring.arch.uaa.model.Project;
import com.spring.arch.uaa.model.Tenant;
import com.spring.arch.uaa.enums.OrganizationType;
import com.spring.arch.uaa.model.Organization;
import com.spring.arch.uaa.model.Project;
import com.spring.arch.uaa.model.Tenant;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.data.repository.Repository;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

/**
 * Organization实体类对应的基础业务Repository
 *
 * @author
 * @version 1.0.0.1
 * @since 2019-12-18 18:41:08
 */
@org.springframework.stereotype.Repository
public interface OrganizationRepository extends Repository<Organization, UUID>, JpaRepository<Organization, UUID>,
        QuerydslPredicateExecutor<Organization> {

    Organization save(Organization model);

//    Organization saveAndFulsh(Organization model);

    @Override
    Optional<Organization> findById(UUID id);

    Optional<Organization> findByParentAndNameAndDisableFalse(Organization parent, String name);

    Optional<Organization> findByNameAndTenantAndDisableFalse(String name, Tenant tenant);

    Page<Organization> findAllByDisableFalse(Pageable pageable);

    @Override
    void deleteById(UUID id);

    List<Organization> findAllByParentIdAndDisableFalseOrderByCreatedDate(UUID ParentId);

    List<Organization> findAllByParentIdAndTypeNotAndDisableFalseOrderByCreatedDate(UUID ParentId, OrganizationType type);

    List<Organization> findByTenantAndDisableFalse(Tenant tenant);

    List<Organization> findByProjectAndDisableFalse(Project project);

    List<Organization> findAllByProjectIdAndTypeAndDisableFalse(UUID projectId, OrganizationType type);

    List<Organization> findAllByDisableFalse();

    Organization findByCodeAndDisableFalse(String tenantRootOrgCode);
}

